.TH C++SIM 3A "23rd December 2016" "C++SIM" "C++SIM Reference Manual"
.SH NAME
Thread \- runtime thread implementation
.SH SYNOPSIS
.B "#ifndef THREAD_H_"
.br
.B "#   include <ClassLib/thread.h>"
.br
.B "#endif"
.sp
.BI "class Thread
.br
.BI "{"
.br
.BI "public:"
.br
.BI "	virtual void Suspend ();"
.br
.BI "	virtual void Resume ();"
.br
.BI "	virtual void Body () = 0;"
.sp
.BI "	virtual long Current_Thread () const;"
.sp
.BI "	virtual long Identity () const;"
.sp
.BI "	static Thread *Self ();"
.sp
.BI "	statid void Exit (int = 0);
.sp
.BI "	static void mainResume ();"
.sp
.BI "protected:"
.br
.BI "	Thread ();"
.br
.BI "	virtual ~Thread ();"
.sp
.BI "	long thread_key;"
.br
.BI "};"
.SH DESCRIPTION
This class defines a template for all thread implementations
used to provide an active object abstraction.

The
.B
Suspend
method is used to suspend the thread to which it is applied.

The
.B
Resume
method resumes the thread it is applied to.

.B
Body
is the main active object code which is executed when the
threaded object is created.

.B
Current_Thread
returns the identity of the currently active thread, or
.B
-1
if an error occurs.

.B
Identity
returns the identity of the threaded object it is applied
to.

.B
Self
returns a pointer to the currently active thread object.

Typically when building your simulation you will have a single process which coordinates the other entities. This coordinator will be its own simulation entity that is created by the main (process) thread, which itself must be suspended while the simulation executes. This means that when the simulation wants to end, the main thread must be resumed. The
.B
mainResume
method should be called by your coordinator entity to have this happen.

If during the execution of your simulation you ever need to exit the entire process, use the
.B
Exit
method and you can pass a specific return code.

.B
thread_key
is used to uniquely identify each threaded object within
the system. It must be set by the actual (derived) thread
class.